package com.qumitech.visualnovel.controller.rest;

import com.alibaba.fastjson.JSONObject;
import com.qumitech.visualnovel.model.common.BaseRsp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.qumitech.visualnovel.service.userLabel.UserLabelService;

import java.util.*;

@RestController
@RequestMapping("/api/userLabel")
public class UserLabelController {

    @Autowired
    private UserLabelService userLabelService;

    @GetMapping("/conf")
    public BaseRsp getUserLabelConf() {
        return userLabelService.getUserLabelConf();
    }

    @GetMapping("/group/option/names")
    public BaseRsp getUserLabelGroupNames() {
        return userLabelService.getUserLabelGroupNames();
    }

    @GetMapping("/group")
    public BaseRsp getUserLabelGroup(
        @RequestParam(value="name", required=false) String name,
        @RequestParam(value="startTime", required=false) String startTime,
        @RequestParam(value="endTime", required=false) String endTime,
        @RequestParam(value="offset", required=false, defaultValue="0") int offset,
        @RequestParam(value="limit", required=false, defaultValue="20") int limit) {
        return userLabelService.getUserLabelGroup(name, startTime, endTime, offset, limit);
    }

    @PostMapping("/group")
    public BaseRsp addUserLabelGroup(@RequestBody JSONObject body) {
        return userLabelService.addUserLabelGroup(body);
    }

    @PutMapping("/group/{id}")
    public BaseRsp modUserLabelGroup(@PathVariable("id") Long id, @RequestBody JSONObject body) {
        return userLabelService.modUserLabelGroup(id, body);
    }

    @DeleteMapping("/group/{id}")
    public BaseRsp delUserLabelGroup(@PathVariable("id") Long id) {
        return userLabelService.delUserLabelGroup(id);
    }
}
